package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     *  分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("listByPage")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageResponse<NursingLevelVo> page = nursingLevelService.getByPage(name, pageNum, pageSize, status);
        return  ResponseResult.success(page);
    }

    /**
     *  查询所有
     * @return
     */
    @GetMapping("listAll")
    @ApiOperation("查询所有")
    public ResponseResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> getAll = nursingLevelService.getByAll();
        return  ResponseResult.success(getAll);
    }

    /**
     * 新增
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation("新增")
    public ResponseResult<NursingLevelDto> insert(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.insert(nursingLevelDto);
        return  ResponseResult.success();
    }

    /**
     *  根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return  ResponseResult.success(nursingLevelVo);
    }

    @PutMapping("update")
    @ApiOperation("修改")
    public ResponseResult<NursingLevelDto> update(@RequestBody  NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return  ResponseResult.success();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public ResponseResult<NursingLevelDto> delete(@PathVariable Long id) {
        nursingLevelService.delete(id);
        return  ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult<NursingLevelDto> enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.enableOrDisable(id, status);
        return  ResponseResult.success();
    }
}
